import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-09-26
 * Time:20:08
 */
public class MyStack {
    public int[] elem;//可以使用泛型
    public int usedSize;


    public MyStack(){
        this.elem = new int[10];
    }
    public boolean isFull(){
        // 数据个数等于长度
        if (usedSize == this.elem.length){
            return true;
        }
        return false;
    }
    public void push(int item){
        if (isFull()){
            //扩容
            this.elem = Arrays.copyOf(this.elem,2 * this.elem.length);
        }
        //存放到数组的最后位置
        this.elem[this.usedSize] = item;
        this.usedSize++;
    }

    public int pop() throws RuntimeException{
        if (empty()){
            throw  new RuntimeException("栈空了");
        }
        int tmp = this.elem[this.usedSize- 1];
        this.usedSize--;
        return tmp;
    }
    public int peek() throws RuntimeException{
        if (empty()){
            throw  new RuntimeException("栈空了");
        }
        return this.elem[this.usedSize - 1];
    }
    public boolean empty(){
        //数据个数为就是空
        if (this.usedSize == 0){
            return true;
        }
        return false;
    }
}
